%normalize NMF factor so that
%all bases has norm 1

function [W,H] = normalizeNMFFactor(W,H,basis)
    switch basis
      case 'W'
        u = sqrt(sum(W.^2, 1));
        W(:,u > 0) = W(:,u > 0) ./ repmat(u(u>0), size(W,1), 1);
        H(:,u > 0) = H(:,u > 0) .* repmat(u(u>0), size(H,1), 1);
      case 'H'
        u = sqrt(sum(H.^2, 1));
        W(:,u > 0) = W(:,u > 0) .* repmat(u(u>0), size(W,1), 1);
        H(:,u > 0) = H(:,u > 0) ./ repmat(u(u>0), size(H,1), 1);
      otherwise
        error('Unknown basis parameter')
    end
end

